package com.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AnnoAdvice {
    @Pointcut("execution( * com.dao.impl.UserDaoImpl.*(..))")
    public void pointcut() {
    }
    @Before("pointcut()")
    public void before(JoinPoint joinPoint) {
        System.out.println("前置通知");
        System.out.println("目标是：" + joinPoint.getTarget());
        System.out.println(",被植入增强处理的目标方法为:"+joinPoint.getSignature().getName());
    }
    @AfterReturning("pointcut()")
    public void afterReturning(JoinPoint joinPoint) {
        System.out.println("这是返回的通知");
        System.out.println(",被植入增强处理的目标方法为:"+joinPoint.getSignature().getName());
    }
    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("这是环绕通知之前的部分");
        Object object = joinPoint.proceed();
        System.out.println("这是环绕通知之后的部分");
        return object;
    }
    @AfterThrowing("pointcut()")
    public void afterThrowing(JoinPoint joinPoint) {
        System.out.println("这是异常通知");
    }
    @After("pointcut()")
    public void after(JoinPoint joinPoint) {
        System.out.println("这是最后置知");
    }
}
